package com.qf.user.controller;

import com.qf.user.service.UserService;
import com.qf.vo.LoginVo;
import com.qf.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin  // 跨域问题处理
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    // username=lisi&password=123456
    @PostMapping("/login1")
    public ResultVo login1(String username,String password){
        log.info("登录请求传入的参数为,username={},password={}",username,password);
        //0 参数校验
        if (username==null||"".equals(username)){
            return new ResultVo(-1, "error", "用户名不能为空");
        }
        if (password==null||"".equals(password)){
            return new ResultVo(-1, "error", "密码不能为空");
        }

        //1. 登录逻辑
        ResultVo resultVo =  userService.login(username,password);


        //2. 返回json
        return resultVo;

    }

    /**
     * {
     *     "username": "zhangsan",
     *     "password": "123456"
     * }
     * @param loginVo
     * @return
     */
    @PostMapping("/login2")
    public ResultVo login2(@RequestBody LoginVo loginVo){
        System.out.println(loginVo);
        return new ResultVo(1, "ok", "slfsljsfsf");
    }

}
